<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下拉框中的默认随机选中项</title>
</head>
<body>
    <!-- 5. 设置下拉框中的默认随机选中项，自己书写结构和js。 -->
    <select name="randonSelected" id="randonSelected">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
    </select>
</body>
<script>
    function getRandomInt(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min)) + min; //不含最大值，含最小值
    }
    var select = document.getElementById("randonSelected");

    var num = parseInt(getRandomInt(0, 5));
    var opts = select.children;
    //将第五个option设置为默认选中
    opts[num].selected = true;
</script>
</html>